<template>
  <div class="box">
    <div class="content">
      <van-sticky>
        <van-nav-bar class="kkk" :title="detaildata.title" left-arrow @click-left="onClickLeft" />
      </van-sticky>

      <div class="top">
        <div class="prompt">
          <p>重要提示:本内容不能作为治疗依据，如有不适请到医院进行科学治疗</p>
        </div>
        <div class="patient-qk">
          <p>{{ detaildata.title }}</p>
        </div>
        <div class="tab-top">
          <div class="left">
            <img :src="detaildata.avatar" alt="" />
          </div>
          <div class="right">
            <p class="doctor">
              <span>{{ detaildata.name }}</span
              ><span>{{ detaildata.type }}</span>
            </p>
            <p>{{ detaildata.cases }}</p>
          </div>
        </div>
        <hr class="line" />
      </div>
      <div class="surgery">
        <div class="surgery-1">
          <p>
            <img src="../../img/huan1.gif" alt="" />
            <span>{{ detaildata.cases }}</span>
          </p>
          <p>
            <span @click="disease(detaildata.id)">疾病百科 ></span>
          </p>
        </div>
      </div>
      <div class="jibing">
        <div class="jb">
          <div>
            <span>疾病</span>
          </div>
          <div>
            <span>{{detaildata.cases}}</span>
          </div>
        </div>
        <div class="zz">
          <div>
            <span>疾病</span>
          </div>
          <div>
            <span>眼睑松弛、内呲赘皮、轻度脸下垂</span>
          </div>
        </div>
      </div>
      <div class="lizi" v-for="(item, index) in bookList" :key="index">
        <p>{{ item.title1 }}</p>
        <p>{{ item.title2 }}</p>
        <p>{{ item.title3 }}</p>
        <p>{{ item.title4 }}</p>
        <p>{{ item.title5 }}</p>
        <p>{{ item.title6 }}</p>
        <p>{{ item.title7 }}</p>
        <p>{{ item.title8 }}</p>
        <div v-if="detaildata.content && detaildata.content.length > 0">
          <p class="biao">{{ detaildata.content[0].ltte }}</p>
          <p>{{ detaildata.content[0].cpap }}</p>
          <p><img :src="detaildata.content[0].img" alt="" /></p>
          <p>{{ detaildata.content[0].cpap }}</p>
          <p>{{ detaildata.content[0].cpap }}</p>
          <p>{{ detaildata.content[0].cpap }}</p>
          <p class="biao">{{ detaildata.content[0].ltte }}</p>
          <p>{{ detaildata.content[0].cpap }}</p>
          <p><img :src="detaildata.content[0].img" alt="" /></p>
          <p>{{ detaildata.content[0].cpap }}</p>
        </div>
      </div>
      <hr class="line-two" />
      <div class="like">
        <p>
          <van-icon class="patient-zan-1" name="star-o"  @click="handleStar(detaildata)" :color="detaildata.collectstate?'red':''"></van-icon
          ><span> {{ detaildata.collect }}</span>
        </p>
        <p>
          <van-icon
            class="patient-zan-1"
            name="like-o"
            @click="handleLike(detaildata)"
            :color="detaildata.praisestate ? 'red' : '#a0a0a0'"
            style=""
          ></van-icon
          ><span> {{ detaildata.praise }}</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import http from '@/utils/http'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useRoute } from 'vue-router'
const router=useRouter();
const route = useRoute()
const patient = JSON.parse(JSON.stringify(route.query))
const detaildata = ref([])
console.log(patient)
// const PatientDetail = async () => {
//   await http.get(`/api/case?id=${patient.id}`).then((res) => {
//     detaildata.value = res.data.data
//     console.log(detaildata)
//   })
// }
// PatientDetail()
const PatientDetail = () => {
  return http
    .get(`/api/case?id=${patient.id}`)
    .then((res) => {
      detaildata.value = res.data.data
      console.log(detaildata)
    })
    .catch((error) => {
      // 这里可以添加合适的错误提示逻辑，比如使用 console.error 打印错误信息或者弹出提示框告知用户数据获取失败等
      console.error('获取患者详细数据失败:', error)
    })
}
PatientDetail()

  .then(() => {
    // 数据获取成功后，如果有需要在这里可以进行一些后续操作，比如触发某些依赖数据渲染的函数等
  })
  .catch((error) => {
    // 再次捕获可能出现的错误，双重保障（虽然和函数内部 catch 有重复，但能确保异常能被处理到）
    console.error('整体获取患者详细数据流程出现错误:', error)
  })
const bookList = [
  {
    title1: '(声明:本文仅用于科普用途，为了保护患者隐私，以下内容里的相关信息已进行处理)',
    title2: '【基本信息】 女，年28岁',
    title3: '【疾病类型】重睑(术后外形不佳)，内眦赘皮，轻度上脸下垂',
    title4: '【既往病史】10年前手术，重脸线外形不佳，两侧不对称，肉条感，睁眼无力，双眼无神',
    title5: '【治疗医院】中国医学科学院皮肤病医院(三级)',
    title6: '【治疗方案】手术(重睑术切开、上睑体肌加海)',
    title7: '【治疗周期】随访2年',
    title8: '【治疗效果】 外形满意，重脸弧度佳,上脸下垂矫正',
    // title9:'患者首诊(2019年12月1日)'
    // title10:'在我们科室，一年四季都能见到带着墨镜出入的患者，哪怕在寒冷的冬季也不例外。'
  },
]
// 收藏
const handleStar = (detaildata) => {
  http.get("/api/collectstate?id=" + detaildata.id).then(res=>{
    if(res.data.msg == '收藏成功'){
      detaildata.collect = detaildata.collect+1
      detaildata.collectstate= true
    }else{
      detaildata.collect = detaildata.collect-1
      detaildata.collectstate=false
    }
  })
  
};
// 点赞
const handleLike = async (detaildata: string) => {
 http.get("/api/praisestate?id=" + detaildata.id).then(res=>{
    if(res.data.msg == '点赞成功!'){
      detaildata.praise = detaildata.praise+1
      detaildata.praisestate= true
    }else{
      detaildata.praise = detaildata.praise-1
      detaildata.praisestate=false
    }
  })
}
// 跳转疾病百科
const disease = async (id: number) => {
  await http.get(`/api/case?id=${id}`).then(() => {
    router.push({ path: '/disease', query: { id: id } })
  })
}
//返回上一级
const onClickLeft = () => history.back()
</script>

<style lang="scss" scoped>
.box {
  width: 90%;
  margin: 0 auto;
  .kkk {
    :root {
      --van-nav-bar-color: #fff; /* 按钮文字颜色设为白色 */
    }
  }
  .content {
    width: 100%;
    height: 100%;
    .kkk {
      padding: 0;
      margin: 0;
    }
    .top {
      width: 100%;
      height: 400px;
      .prompt {
        font-size: 24px;
        color: #ccc;
        margin-top: 20px;
      }
      .patient-qk {
        margin-top: 20px;
        width: 100%;
        height: 100px;
        padding: 10px;
        line-height: 70px;
        p {
          font-size: 38px;
          font-weight: 500;
        }
      }
      .tab-top {
        margin-top: 20px;
        width: 100%;
        height: 140px;
        display: flex;
        padding: 10px;
        .left {
          width: 20%;
          height: 140px;
          padding: 10px;
          img {
            width: 90px;
            height: 90px;
            border-radius: 50%;
          }
        }
        .right {
          width: 80%;
          height: 90px;
          padding: 10px;
          .doctor {
            width: 100%;
            height: 40px;
            line-height: 40px;
            margin-top: 20px;
            span {
              margin-left: 10px;
            }
            :nth-child(1) {
              font-size: 30px;
              font-weight: bold;
            }
            :nth-child(2) {
              border: 2px solid #0d42ac;
              padding: 7px;
              border-radius: 30px;
              color: #0d42ac;
            }
          }
          :nth-child(2) {
            margin-top: 5px;
            color: #959a96;
            padding-left: 10px;
          }
        }
      }
      .line {
        margin-top: 40px;
        border: 1px solid #ededed;
      }
    }
    .surgery {
      width: 100%;
      height: 140px;
      .surgery-1 {
        width: 100%;
        height: 100px;
        background: #e8efff;
        border-radius: 15px;
        display: flex;
        justify-content: space-between;
        p {
          margin: 30px;
          display: flex;
          text-align: center;
          line-height: 40px;
          span {
            width: 100%;
            height: 100%;
            padding-bottom: 40px;
            margin-left: 20px;
            font-weight: 600;
          }
          img {
            width: 45px;
            height: 45px;
          }
        }
        :nth-child(2) {
          span {
            color: #c2cbd4;
            font-weight: 300;
          }
        }
      }
    }
    .jibing {
      width: 100%;
      height: 150px;
      border: 1px solid #efefef;
      border-radius: 20px;
     
      .jb {
        width: 100%;
        height: 75px;
        display: flex;
        :nth-child(1) {
          width: 20%;
          height: 75px;
          text-align: center;
          line-height: 75px;
          border: 1px solid #efefef;
          border-top: 0;
          border-left: 0;
          span {
            color: #c3c3c3;
          }
        }
        :nth-child(2) {
          width: 80%;
          height: 75px;
          line-height: 75px;
          padding-left: 30px;
          border: 1px solid #efefef;
          border-top: 0;
          border-left: 0;
          border-right: 0;
        }
      }
      .zz {
        width: 100%;
        height: 75px;
        display: flex;
        :nth-child(1) {
          width: 20%;
          height: 75px;
          text-align: center;
          line-height: 75px;
          border: 1px solid #efefef;
          border-top: 0;
          border-left: 0;
          border-bottom: 0;
          span {
            color: #c3c3c3;
          }
        }
        :nth-child(2) {
          width: 80%;
          height: 75px;
          line-height: 75px;

          padding-left: 30px;
        }
      }
    }
    .lizi {
      width: 100%;
      height: 100%;
      margin-top: 70px;
      p {
        padding: 0 10px;
        font-size: 30px;
        margin-top: 30px;
        line-height: 70px;
        img {
          width: 100%;
          height: 500px;
          border-radius: 20px;
        }
      }

      .biao {
        font-size: 40px;
        font-weight: 600;
      }
    }
    .line-two {
      display: flex;
      margin-top: 50px;
    }
    .like {
      margin-top: 50px;
      width: 100%;
      height: 200px;
      display: flex;
      justify-content: center;
      p {
        display: flex;
        padding: 9px 70px;
        width: 200px;
        height: 60px;
        border: 1px solid #ededed;
        margin-left: 30px;
        border-radius: 20px;
        .patient-zan-1 {
          font-size: 40px;
        }
        span {
          margin-left: 20px;
          padding: 10px 0;
        }
      }
    }
  }
}
</style>